{% extends 'base.html' %}

{% block title %}登录{% endblock %}

{% block content %}
<div class="row justify-content-center mt-5">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h4 class="mb-0">用户登录</h4>
            </div>
            <div class="card-body">
                <!-- 显示错误信息 -->
                {% if form.errors %}
                <div class="alert alert-danger" role="alert">
                    用户名或密码不正确，请重新输入！
                </div>
                {% endif %}

                <!-- 登录表单 -->
                <form method="post">
                    {% csrf_token %}
                    <!-- 隐藏字段：登录成功后跳回之前的“添加商品”页面 -->
                    <input type="hidden" name="next" value="{{ next }}">

                    <div class="mb-3">
                        <label for="{{ form.username.id_for_label }}" class="form-label">用户名</label>
                        <!-- 移除 add_class 过滤器，改用原始表单字段 -->
                        <input type="text" name="{{ form.username.html_name }}"
                               id="{{ form.username.id_for_label }}"
                               class="form-control"
                               value="{{ form.username.value|default:'' }}">
                    </div>

                    <div class="mb-3">
                        <label for="{{ form.password.id_for_label }}" class="form-label">密码</label>
                        <!-- 移除 add_class 过滤器，改用原始表单字段 -->
                        <input type="password" name="{{ form.password.html_name }}"
                               id="{{ form.password.id_for_label }}"
                               class="form-control">
                    </div>

                    <button type="submit" class="btn btn-primary w-100">登录</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
